/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package is.ru.domain;

import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author davidhalldor
 */
public class TestData {
    private List<Course> appetizers;
    private List<Course> mainCourses;
    private List<Course> desserts;
    private List<Ingredient> ingredientsList;
    private int idCount;
    
    public TestData() {
        appetizers = new ArrayList <Course>();
        mainCourses = new ArrayList <Course>();
        desserts = new ArrayList <Course>();
        ingredientsList = new ArrayList <Ingredient>();
        idCount = 0;
        
    }

    public List<Course> getAppetizers() {
        return appetizers;
    }

    public void setAppetizers(List<Course> appetizers) {
        this.appetizers = appetizers;
    }

    public List<Course> getMainCourses() {
        return mainCourses;
    }

    public void setMainCourses(List<Course> mainCourses) {
        this.mainCourses = mainCourses;
    }

    public List<Course> getDesserts() {
        return desserts;
    }

    public void setDesserts(List<Course> desserts) {
        this.desserts = desserts;
    }

    public Double getTotalSum() {
        Double totalSum = 0.0;
        for (Ingredient ingredient : this.ingredientsList) {
            if (!ingredient.isPurchased()) {
                 totalSum += ingredient.getCost(); 
            }  
        }
        return totalSum;
    }
    
    public Course getAppetizersByName(String name) {
        for (Course course : appetizers) {
            if (course.getName().equalsIgnoreCase(name)) { 
                return course;
            }
        }
        return null;
    }

    public List<Ingredient> getIngredientsList() {
        return ingredientsList;
    }

    public void addIngredientToList(Ingredient ingredient) {
        this.ingredientsList.add(ingredient);
    }
    
    public void removeIngredientFromListByName(String name) {      
        if (this.ingredientsList.size() > 0) {
            for (int i = 0; i < this.ingredientsList.size(); i++) {    
                Ingredient ingredient = this.ingredientsList.get(i);
                if (ingredient.getName().equalsIgnoreCase(name)) {
                    this.ingredientsList.remove(ingredient);
                }
            }
        }
    }
    
    public Course getMainCoursesByName(String name) {
        for (Course course : mainCourses) {
            if (course.getName().equalsIgnoreCase(name)) { 
                return course;
            }
        }
        return null;
    }
    
    public Course getDessertsByName(String name) {
        for (Course course : desserts) {
            if (course.getName().equalsIgnoreCase(name)) { 
                return course;
            }
        }
        return null;
    }
    
    public Course getSideCourseByName(String name) {
        for (Course course : mainCourses) {
            if (course.getSideCoursesList() != null) {
                for (Course sideCourse : course.getSideCoursesList()) {
                    if (sideCourse.getName().equalsIgnoreCase(name)) {
                        return sideCourse;
                    }
                }
            }
        }
        return null;
    }
    
    public void resetData() {
        ingredientsList.clear();
    }
    
    public void generateTestData() {
        generateDesserts();
        generateAppetizers();
        generateMainCourses();
    }
    
    private void generateAppetizers() {
        List<Ingredient> onionSoupIngredients = new ArrayList<Ingredient>();
        List<Ingredient> hotWingsIngredients = new ArrayList<Ingredient>();
        
        Course onionSoup = new Course();
        onionSoup.setName("Onion Soup");
        
        Ingredient onion = new Ingredient();
        onion.setId(idCount++);
        onion.setName("Onion");
        onion.setAmmount(2.0);
        onion.setMeasure("pcs.");
        onion.setCost(100.0);
        onion.setPurchased(false);
        onionSoupIngredients.add(onion);
        
        Ingredient water = new Ingredient();
        water.setId(idCount++);
        water.setName("Water");
        water.setAmmount(0.5);
        water.setCost(0.0);
        water.setMeasure("l.");
        water.setPurchased(false);
        onionSoupIngredients.add(water);
        
        onionSoup.setIngredientsList(onionSoupIngredients);
  
        appetizers.add(onionSoup);
        
        Course hotWings = new Course();
        hotWings.setName("Hot Wings");
        
        Ingredient chickenLegs = new Ingredient();
        chickenLegs.setId(idCount++);
        chickenLegs.setName("Chicken Legs");
        chickenLegs.setAmmount(3.0);
        chickenLegs.setMeasure("pcs.");
        chickenLegs.setCost(300.0);
        chickenLegs.setPurchased(false);
        hotWingsIngredients.add(chickenLegs);
        
        Ingredient hotWingSouce = new Ingredient();
        hotWingSouce.setId(idCount++);
        hotWingSouce.setName("Hot Wings Souce");
        hotWingSouce.setAmmount(2.0);
        hotWingSouce.setCost(150.0);
        hotWingSouce.setMeasure("dl.");
        hotWingSouce.setPurchased(false);
        hotWingsIngredients.add(hotWingSouce);
 
        hotWings.setIngredientsList(hotWingsIngredients);
  
        appetizers.add(hotWings);
    }
    
    private void generateMainCourses() {
        List<Ingredient> beefFilletIngredients = new ArrayList<Ingredient>();
        List<Ingredient> salmonIngredients = new ArrayList<Ingredient>();
        
        Course beefFillet = new Course();
        beefFillet.setName("Beef Fillet");
        
        Ingredient beefFillet1 = new Ingredient();
        beefFillet1.setId(idCount++);
        beefFillet1.setName("Beef Fillet");
        beefFillet1.setAmmount(200.0);
        beefFillet1.setMeasure("gr.");
        beefFillet1.setCost(1000.0);
        beefFillet1.setPurchased(false);
        beefFilletIngredients.add(beefFillet1);
        
        Ingredient blackPepper = new Ingredient();
        blackPepper.setId(idCount++);
        blackPepper.setName("Black Pepper");
        blackPepper.setAmmount(0.5);
        blackPepper.setCost(10.0);
        blackPepper.setMeasure("tsp.");
        blackPepper.setPurchased(false);
        beefFilletIngredients.add(blackPepper);
        
        beefFillet.setIngredientsList(beefFilletIngredients);
  
        List<Course> sideCourses = new ArrayList<Course>();
        List<Ingredient> pepperSouceIngredients = new ArrayList<Ingredient>();
        List<Ingredient> bernieSouceIngredients = new ArrayList<Ingredient>();
        
        Course pepperSouce = new Course();
        pepperSouce.setName("Pepper Souce");
        
        Ingredient vegatableOil = new Ingredient();
        vegatableOil.setId(idCount++);
        vegatableOil.setName("vegatable oil");
        vegatableOil.setAmmount(2.5);
        vegatableOil.setMeasure("ml.");
        vegatableOil.setCost(5.0);
        vegatableOil.setPurchased(false);
        pepperSouceIngredients.add(vegatableOil);
        
        Ingredient whiteWine = new Ingredient();
        whiteWine.setId(idCount++);
        whiteWine.setName("white wine");
        whiteWine.setAmmount(150.0);
        whiteWine.setCost(500.0);
        whiteWine.setMeasure("ml.");
        whiteWine.setPurchased(false);
        pepperSouceIngredients.add(whiteWine);
        
        pepperSouce.setIngredientsList(pepperSouceIngredients);
        sideCourses.add(pepperSouce);
        
        Course bernieSouce = new Course();
        bernieSouce.setName("Bernie Souce");
        
        Ingredient butter = new Ingredient();
        butter.setId(idCount++);
        butter.setName("butter");
        butter.setAmmount(2.5);
        butter.setMeasure("ml.");
        butter.setCost(7.0);
        butter.setPurchased(false);
        bernieSouceIngredients.add(butter);
        
        Ingredient milk = new Ingredient();
        milk.setId(idCount++);
        milk.setName("milk");
        milk.setAmmount(110.0);
        milk.setCost(65.0);
        milk.setMeasure("dl.");
        milk.setPurchased(false);
        bernieSouceIngredients.add(milk);
        
        bernieSouce.setIngredientsList(bernieSouceIngredients);
        sideCourses.add(bernieSouce);
        
        beefFillet.setSideCoursesList(sideCourses);
        
        mainCourses.add(beefFillet);
        
        Course salmon = new Course();
        salmon.setName("Salmon");
        
        Ingredient salmon1 = new Ingredient();
        salmon1.setId(idCount++);
        salmon1.setName("Salmon");
        salmon1.setAmmount(200.0);
        salmon1.setMeasure("gr.");
        salmon1.setCost(800.0);
        salmon1.setPurchased(false);
        salmonIngredients.add(salmon1);
        
        Ingredient sitrusPepper = new Ingredient();
        sitrusPepper.setId(idCount++);
        sitrusPepper.setName("Sitrus Pepper");
        sitrusPepper.setAmmount(0.5);
        sitrusPepper.setCost(12.0);
        sitrusPepper.setMeasure("dl.");
        sitrusPepper.setPurchased(false);
        salmonIngredients.add(sitrusPepper);
 
        salmon.setIngredientsList(salmonIngredients);
  
        mainCourses.add(salmon);
    }
    
    private void generateDesserts() {
        List<Ingredient> applePieIngredients = new ArrayList<Ingredient>();
        List<Ingredient> chocolateCakeIngredients = new ArrayList<Ingredient>();
        
        Course applePie = new Course();
        applePie.setName("Apple Pie");
        
        Ingredient apple = new Ingredient();
        apple.setId(idCount++);
        apple.setName("apple");
        apple.setAmmount(3.0);
        apple.setMeasure("pcs.");
        apple.setCost(300.0);
        apple.setPurchased(false);
        applePieIngredients.add(apple);
        
        Ingredient wheat = new Ingredient();
        wheat.setId(idCount++);
        wheat.setName("wheat");
        wheat.setAmmount(100.0);
        wheat.setCost(100.0);
        wheat.setMeasure("gr.");
        wheat.setPurchased(false);
        applePieIngredients.add(wheat);
        
        applePie.setIngredientsList(applePieIngredients);
  
        desserts.add(applePie);
        
        Course chocolateCake = new Course();
        chocolateCake.setName("Chocolate Cake");
        
        Ingredient darkChocolate = new Ingredient();
        darkChocolate.setId(idCount++);
        darkChocolate.setName("70% Chocolate");
        darkChocolate.setAmmount(250.0);
        darkChocolate.setMeasure("gr.");
        darkChocolate.setCost(300.0);
        darkChocolate.setPurchased(false);
        chocolateCakeIngredients.add(darkChocolate);
        
        Ingredient wheat2 = new Ingredient();
        wheat2.setId(idCount++);
        wheat2.setName("wheat");
        wheat2.setAmmount(150.0);
        wheat2.setCost(150.0);
        wheat2.setMeasure("gr.");
        wheat2.setPurchased(false);
        chocolateCakeIngredients.add(wheat2);
 
        chocolateCake.setIngredientsList(chocolateCakeIngredients);
  
        desserts.add(chocolateCake);
    }
}
